// 测试用例
describe('majorityElement', () => {
    test('返回数组中的主元素', () => {
      expect(majorityElement([1, 2, 3, 2, 2])).toBe(2);
      expect(majorityElement([1, 2, 3, 3, 3])).toBe(3);
    });
  
    test('抛出错误：输入必须为数组', () => {
      expect(() => majorityElement(123)).toThrow("输入必须为数组");
      expect(() => majorityElement(null)).toThrow("输入必须为数组");
      expect(() => majorityElement(undefined)).toThrow("输入必须为数组");
      expect(() => majorityElement({})).toThrow("输入必须为数组");
    });
  
    test('抛出错误：数组不能为空', () => {
      expect(() => majorityElement([])).toThrow("数组不能为空");
    });
  
    test('抛出错误：数组中不存在主元素', () => {
      expect(() => majorityElement([1, 2, 3])).toThrow("数组中不存在主元素");
      expect(() => majorityElement([1, 2, 3, 4, 5])).toThrow("数组中不存在主元素");
    });
  });